/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Codec;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

/**
 *
 * @author Nhan Nguyen
 */
public class MessageCodecFactory  implements ProtocolCodecFactory
{
    private ProtocolEncoder encoder;
    private ProtocolDecoder decoder;

    public static MessageCodecFactory getInstance() {
        return InstanceHolder.INSTANCE;
    }

    private static final class InstanceHolder {

        private static final MessageCodecFactory INSTANCE = new MessageCodecFactory();
    }

    public MessageCodecFactory()    {
        encoder = MessageRequestEncoder.getInstance();
        decoder = MessageRequestDecoder.getInstance();
    }

    public ProtocolEncoder getEncoder(IoSession is) throws Exception {
        return encoder;
    }

    public ProtocolDecoder getDecoder(IoSession is) throws Exception {
        return decoder;
    }
}
